﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace WindowsStateService.Data
{
    public class MonitorLimitPara
    {
        IList<NetInfo> ids = new List<NetInfo>();
        public int CpuUsage 
        {
            get;set;        
        }

        public int CpuTemperature
        {
            get;
            set;
        }

        public int UsedMemoryRatio
        {
            get;
            set;
        }

        public int DiskUsage
        {
            get;
            set;
        }

        public int DiskTemperature
        {
            get;
            set;
        }

        public int MainBoardTemperature
        {
            get;
            set;
        }

        public int FanSpeed
        {
            get;
            set;
        }

        public bool EnableCpuUsage
        {
            get;
            set;
        }
        public bool EnableCpuTemperature
        {
            get;
            set;
        }
        public bool EnableUsedMemoryRatio
        {
            get;
            set;
        }
        public bool EnableDiskUsage
        {
            get;
            set;
        }
        public bool EnableDiskTemperature
        {
            get;
            set;
        }
        public bool EnableMainBoardTemperature
        {
            get;
            set;
        }
        public bool EnableFanSpeed
        {
            get;
            set;
        }

        public bool EnableNetMonite
        {
            get;
            set;
        }
        public IList<NetInfo> NetIds
        {
            get { return ids; }
            set { ids = value; }
        }


        public bool NeedGetCpuInfo()
        {
            return EnableCpuUsage || EnableCpuTemperature;
        }

        public bool NeedGetMemoryInfo()
        {
            return EnableUsedMemoryRatio;
        }

        public bool NeedGetDiskInfo()
        {
            return EnableDiskTemperature || EnableDiskUsage;
        }

        public bool NeedGetMainBoardInfo()
        {
            return EnableMainBoardTemperature || EnableFanSpeed;
        }


        public override string ToString()
        {
            Type t = this.GetType();
            PropertyInfo[] properties = t.GetProperties();
            IList<string> strs = new List<string>();
            foreach(var property in properties)
            {
                switch(property.Name)
                {
                    case "EnableCpuUsage":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("CPU使用率");
                        }
                        break;
                    case "EnableCpuTemperature":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("CPU温度");
                        }
                        break;
                    case "EnableUsedMemoryRatio":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("已使用内存");
                        }
                        break;
                    case "EnableDiskUsage":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("磁盘使用率");
                        }
                        break;
                    case "EnableDiskTemperature":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("磁盘温度");
                        }
                        break;
                    case "EnableMainBoardTemperature":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            //strs.Add("主板温度");
                        }
                        break;
                    case "EnableFanSpeed":
                        if ((bool)(property.GetValue(this, null)))
                        {
                            //strs.Add("风扇转速");
                        }
                        break;
                    case "EnableNetMonite":
                        if((bool)(property.GetValue(this, null)))
                        {
                            strs.Add("网络监控");
                        }
                        break;
                }
            }
            if(strs.Count == 0)
            {
                return "请至少选择一个监控参数。";
            }
            return string.Join("|", strs) + " 已开启。";
        }

        public void InitFrom(MonitorLimitPara para)
        {
            this.CpuTemperature = para.CpuTemperature;
            this.CpuUsage = para.CpuUsage;
            this.DiskTemperature = para.DiskTemperature;
            this.DiskUsage = para.DiskUsage;
            this.EnableCpuTemperature = para.EnableCpuTemperature;
            this.EnableCpuUsage = para.EnableCpuUsage;
            this.EnableDiskTemperature = para.EnableDiskTemperature;
            this.EnableDiskUsage = para.EnableDiskUsage;
            this.EnableFanSpeed = para.EnableFanSpeed;
            this.EnableMainBoardTemperature = para.EnableMainBoardTemperature;
            this.EnableNetMonite = para.EnableNetMonite;
            this.EnableUsedMemoryRatio = para.EnableUsedMemoryRatio;
            this.FanSpeed = para.FanSpeed;
            this.ids.Clear();
            foreach(var id in para.ids)
            {
                this.ids.Add(id);
            }
            this.MainBoardTemperature = para.MainBoardTemperature;
            this.UsedMemoryRatio = para.UsedMemoryRatio;
        }
    }
}
